//
//  AudioRecorder.h
//  AudioUnitDemo
//
//  Created by ilongge on 2021/9/1.
//

 

#import <Foundation/Foundation.h>

typedef NS_ENUM (UInt32, AudioRecorderSampleRate) {
    AudioRecorderSampleRate_8000 = 8000,
    AudioRecorderSampleRate_22050 = 22050,
    AudioRecorderSampleRate_44100 = 44100,
    AudioRecorderSampleRate_48000 = 48000,
    AudioRecorderSampleRate_96000 = 96000,
    AudioRecorderSampleRate_192000 = 192000,
    AudioRecorderSampleRate_256000 = 256000,
    AudioRecorderSampleRate_Other = 0,
};

typedef NS_ENUM (UInt32, AudioRecorderChannel) {
    // 单声道
    AudioRecorderChannel_Mono = 1,
    // 立体声
    AudioRecorderChannel_Stereo = 2
};

@interface AudioRecorderDescription : NSObject
/**
 期望音频采样率
 */
@property (nonatomic, assign) AudioRecorderSampleRate preferredSampleRate;

/**
 期望录音声道数
 除非使用外部硬件进行录制，否则通常使用单声道录制
 默认 AudioRecorderChannel_Mono
 */
@property (nonatomic, assign) AudioRecorderChannel preferredInputChannels;
/**
 期望播放声道数
 默认 AudioRecorderChannel_Mono
 */
@property (nonatomic, assign) AudioRecorderChannel preferredOuputChannels;
/**
 期望录音回调间隔
 越小越灵敏
 默认 200 / sampleRate
 */
@property (nonatomic, assign) NSTimeInterval preferredIOBufferDuration;
/**
 缓存大小 64 -- 1024
 */
@property (nonatomic, assign) NSTimeInterval preferredDiskBufferSize;

/**
 实际音频采样率
 */
- (AudioRecorderSampleRate)sampleRate;

/**
 实际录音声道数
 */
- (AudioRecorderChannel)inputChannels;

/**
 实际播放声道数
 */
- (AudioRecorderChannel)ouputChannels;

/**
 实际录音回调间隔
 */
- (NSTimeInterval)IOBufferDuration;

/**
 开启音频数据缓存
 */
@property (nonatomic, assign, getter=isEnableDiskBuffer) BOOL enableDiskBuffer;

/**
 音频缓存大小 Byte
 */
@property (nonatomic, assign) NSInteger diskBufferSize;

/**
 是否开启耳返
 */
@property (nonatomic, assign, getter=isEnablePlayWhenRecord) BOOL enablePlayWhenRecord;

+ (instancetype)defaultRecorderDescription;

@end


@interface AudioRecorder : NSObject

@property (nonatomic, strong, readonly) AudioRecorderDescription *recorderDescription;

#pragma mark ************** Method

/**
 初始化
 */

- (instancetype)initWithPreferredRecorderDescription:(AudioRecorderDescription *)preferredRecorderDescription;

/**
 开始录音
 */
- (void)startAudioRecord;
/**
 暂停录音
 */
- (void)pauseAudioRecord;

/**
 继续录音
 */
- (void)continueAudioRecord;

/**
 结束录音
 返回录音路径
 */
- (NSString *)stopAudioRecord;
   

@end


